#ifndef SPIDERMESSAGE_H_
#define SPIDERMESSAGE_H_

#include <stdint.h>

enum {
    MESSAGE_REGISTER_REQ = 0,
    MESSAGE_REGISTER_RESP,
    MESSAGE_HEARTBEAT_REQ,
    MESSAGE_HEARTBEAT_RESP,
    MESSAGE_TCP_REQ,
    MESSAGE_TCP_RESP,
    MESSAGE_UDP_REQ,
    MESSAGE_UDP_RESP,
};

#define UDID_SIZE       (33)
#define NONCE_SIZE      (9)
#define CHECKCODE_SIZE  (33)

typedef struct __attribute__((packed))  {
    uint16_t type;
} MessageHeader;

typedef struct __attribute__((packed))  {
    MessageHeader header;
    char udid[UDID_SIZE];
    char nonce[NONCE_SIZE];
    char cipher[CHECKCODE_SIZE];
} MessageRegister;

typedef struct __attribute__((packed))  {
    MessageHeader header;
    uint16_t code;
    uint32_t commandTimeout;
    uint32_t idleTimeout;
} MessageRegisterResp;

typedef struct __attribute__((packed))  {
    MessageHeader header;
    uint64_t timestamp;
} MessageHeartbeat;

typedef struct __attribute__((packed))  {
    MessageHeader header;
    uint32_t sessionId;
} MessageRelay;

typedef struct __attribute__((packed))  {
    MessageHeader header;
    uint32_t sessionId;
    uint32_t eagleAddr;
    uint16_t eaglePort;
    uint16_t targetPort;
    uint16_t targetLen;
    uint8_t  target[];
} MessageTcp;

typedef struct __attribute__((packed))  {
    MessageHeader header;
    uint32_t sessionId;
    uint32_t eagleAddr;
    uint16_t eaglePort;
    uint16_t targetPort;
} MessageUdp;

#endif